<?php


namespace App\Http\Controllers\Api\V1\Front\User;


use App\Http\Controllers\Controller;
use App\Models\Good;
use App\Models\GoodAllocation;
use App\Models\GoodStock;
use App\Models\Partition;
use App\Models\Post;
use App\Models\Region;
use App\Models\User;
use App\Models\Merchant;
use App\Models\Casus;
use App\Models\PostBanner;
use App\Models\PostBannerShop;
use App\Models\UserAuthorization;
use App\Models\UserContract;
use App\Models\UserContractLog;
use App\Models\UserCredit;
use App\Models\UserH5;
use App\Models\UserInformation;
use App\Models\userLikeKeyValue;
use App\Models\UserFollow;
use App\Models\Comment;
use App\Models\CommentReply;
use App\Models\CommentLike;
use App\Models\UserLike;
use App\Models\UserCollect;
use App\Models\UserApply;
use App\Models\PrivateLetter;
use App\Models\PrivateContent;
use App\Models\BalanceLog;
use App\Models\Order;
use App\Models\UserOperator;
use App\Models\Applet;
use App\Models\UserLevel;
use App\Models\UserClient;
use App\Models\Combo;
use App\Models\Setting;
use App\Libs\httpUtil;
use App\Libs\WXBizDataCrypt;
use App\Models\UserPriceLog;
use App\Models\UserRelation;
use App\Models\UserShoppingCart;
use App\Models\UserShoppingCollect;
use App\Models\UserShoppingLink;
use App\Services\Front\IndexService;
use Illuminate\Http\Request;

class UserController extends Controller
{
    /**
     * 用户详情
     * @param Request $request [description]
     * @return [type]           [description]
     */
    public function userInfo(Request $request)
    {
        $userId = $request->USERID;
        $user = User::select('t1.userId', 't1.membershipId', 't1.level', 't1.postId', 't2.postName', 't1.regionIdList', \DB::raw('null as regionName'), 't3.userName', 't3.sex', 't3.birthday', 't3.phone'
            , 't3.standbyContact', 't3.standbyContactPhone', 't3.email', 't3.WX', 't3.cardNumber', 't3.frontCardImg', 't3.managerCardImg', 't3.province', 't3.city', 't3.area', 't3.street', 't3.detail', 't3.companyInauguration'
            , 't3.hireDate', 't3.companyPost', 't3.companyMajor', 't3.specialHobby', 't3.introduction', 't3.graduationSchool', 't3.graduationTime', 't3.graduationMajor', 't3.personalPhoto', 't3.jobResume', 't1.enabledStatus'
            , 't4.contractTime', 't4.expireTime', 't4.expireDay', 't4.contractFile', 't4.reviewInformation', 't4.creditRating', 't1.inviteUserNum', 't1.affiliationProvince', 't1.affiliationCity', 't1.affiliationArea', 't1.affiliationStreet'
            , 't1.affiliationDetail', 't1.partitionId', 't5.partitionName', 't1.inviteUserId', 't1.inviteMembershipId', 't1.isBrilliant', 't1.isFront', 't1.isCentre', 't1.centreJurisdiction', 't1.isManager', 't1.managerJurisdiction'
            , 't1.password', 't1.logoutStatus', 't1.logoutBreak', 't1.userLockStatus', 't1.lockBreak', 't1.createTime', 't1.logoutTime', 't1.isPublicJobResume')
            ->from((new User())->getTable() . ' as t1')
            ->leftJoin((new Post())->getTable() . ' as t2', 't1.postId', '=', 't2.postId')
            ->join((new UserInformation())->getTable() . ' as t3', 't1.userId', '=', 't3.userId')
            ->leftJoin((new UserContract())->getTable() . ' as t4', 't1.userId', '=', 't4.userId')
            ->leftJoin((new Partition())->getTable() . ' as t5', 't1.partitionId', '=', 't5.partitionId')
            ->where('t1.userId', $userId)
            ->first();
        $regionName = null;
        if ($user['regionIdList']) {
            $regionIdList = explode(';', $user['regionIdList']);
            $regionList = Region::select('regionName')->whereIn('regionId', $regionIdList)->get()->toArray();
            foreach ($regionList as $value) {
                if ($regionName) {
                    $regionName = $regionName . ";" . $value['regionName'];
                } else {
                    $regionName = $value['regionName'];
                }
            }
        }
        $user['followNum'] = UserFollow::where('followUserId', $userId)->count();
        $user['attentionNum'] = UserFollow::where('userId', $userId)->count();
        $user['regionName'] = $regionName;
        return $this->apiResponse($user);
    }
}
